package dao;

import java.util.Date;

import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

import model.ServerLogEntry;
import model.User;
import enumerations.LogType;

/**
 * Session Bean implementation class ServerLogEntryDao
 * 
 * @author zahariem
 */
@Stateless
@LocalBean
public class ServerLogEntryDao {
	
	@PersistenceContext
	EntityManager em;

	@Resource
	UserTransaction ut;

    /**
     * Default constructor. 
     */
    public ServerLogEntryDao() {
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @author zahariem
     *  
     * @param type tipul operatiei
     * @param content 
     * @param date 
     * @param sender este cel care a facut opertia
     */
    public void insertOpToLog(LogType type, String content, Date date, User sender) {
		try {
			
			if (type != null) {
				ServerLogEntry sle = new ServerLogEntry();
				sle.setLogType(type);
				sle.setContent(content);
				sle.setDate(date);
				sle.setSender(sender);
				em.persist(sle);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
